package com.ewanghuiju.app.ui.pintuan.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.Target;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;

/**
 * @author sj  qq:751943509
 * @class 商品详情
 * @time 2020/2/20
 */
public class PintuanShopDetailsAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    public PintuanShopDetailsAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        ImageView imageview = helper.getView(R.id.imageview);

//        Glide.with(mContext)
//                .asBitmap()
//                .load(item)
//                .dontAnimate()//解决第一次加载不显示bug
//                .apply(new RequestOptions().placeholder(R.mipmap.icon_error_picture).error(R.mipmap.icon_error_picture))
//                .into(new ImageViewTarget<Bitmap>(imageview) {
//                    @Override
//                    public void onLoadStarted(@Nullable Drawable placeholder) {
//                        super.onLoadStarted(placeholder);
//                    }
//
//                    @Override
//                    public void onLoadFailed(@Nullable Drawable errorDrawable) {
//                        super.onLoadFailed(errorDrawable);
//                    }
//
//                    @Override
//                    protected void setResource(@Nullable Bitmap resource) {
//                        if (resource != null) {
//                            boolean eqLongImage = MediaUtils.isLongImg(resource.getWidth(),
//                                    resource.getHeight());
//                            longImageview.setVisibility(eqLongImage ? View.VISIBLE : View.GONE);
//                            imageview.setVisibility(eqLongImage ? View.GONE : View.VISIBLE);
//                            if (eqLongImage) {
//                                // 加载长图
//                                longImageview.setQuickScaleEnabled(false);
//                                longImageview.setZoomEnabled(false);
//                                longImageview.setPanEnabled(false);
//                                longImageview.setDoubleTapZoomDuration(100);
//                                longImageview.setMinimumScaleType(SubsamplingScaleImageView.SCALE_TYPE_CENTER_CROP);
//                                longImageview.setDoubleTapZoomDpi(SubsamplingScaleImageView.ZOOM_FOCUS_CENTER);
//                                longImageview.setImage(ImageSource.bitmap(resource),
//                                        new ImageViewState(0, new PointF(0, 0), 0));
//                            } else {
//                                 普通图片
//                                imageview.setImageBitmap(resource);
//                                imageview.setImageBitmap(ImageUtil.bytes2Bitmap(ImageUtil.compressByQuality(resource,1024,true)));
//                                imageview.setImageBitmap(ImageUtil.compressBySampleSize(resource,2,false));
//                            }
//                        }
//                    }
//                });
//        GlideEngine.createGlideEngine().loadImage(mContext, item, imageview, longImageview, null);

        Glide.with(mContext)
//                .asDrawable()
                .load(item)
                .dontAnimate()//解决第一次加载不显示bug
                .placeholder(R.mipmap.icon_error_picture)//图片加载出来前，显示的图片
                .error(R.mipmap.icon_error_picture)//图片加载失败后，显示的图片
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
//                .override(Target.SIZE_ORIGINAL, App.getInstance().SCREEN_HEIGHT == 0 ? Target.SIZE_ORIGINAL : (App.getInstance().SCREEN_HEIGHT * 3))
                .into(imageview);

    }
}
